class Singleton {
    // 实例作为静态的私有属性
    private static instance: Singleton = new Singleton();
    public name: string;
  
    // 构造函数为私有的
    private constructor(name: string = 'Lynch') {
      this.name = name;
    }
  
    // 向外输出实例的，只有这一个静态的方法
    public static getInstance() {
      return this.instance;
    }
  }
  
  // 输出 Lynch
  let single = Singleton.getInstance();
  console.log(single.name);
  
  // 输出 true，因为 single 和 single2 指向同一个实例
  let single2 = Singleton.getInstance();
  console.log(single === single2);
  
  // 都会输出 Sucker
  single.name = 'Sucker';
  console.log(single.name);
  console.log(single2.name);